/**
 * @Author 天下无敌
 * @Date 
 * @AIDE AIDE+ 
 */
package com.ecs.core.gsystem;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.artemis.BaseSystem;
import com.badlogic.gdx.math.Rectangle;

public class CameraSystem extends BaseSystem {

    private final OrthographicCamera worldCamera;
	private final Rectangle cameraBounds = new Rectangle();

    public CameraSystem(OrthographicCamera camera) {
		super();
        this.worldCamera = camera;
    }

    public OrthographicCamera getCamera() {
        return worldCamera;
    }

	public boolean contains(float x, float y)
	{
		return cameraBounds.contains(x,y);
	}

	public boolean overlaps(Rectangle r)
	{
		return cameraBounds.overlaps(r);
	}

	public void updata(){
		float width = worldCamera.viewportWidth * worldCamera.zoom;
        float height = worldCamera.viewportHeight * worldCamera.zoom;
        float w = width * Math.abs(worldCamera.up.y) + height * Math.abs(worldCamera.up.x);
        float h = height * Math.abs(worldCamera.up.y) + width * Math.abs(worldCamera.up.x);
        cameraBounds.set(worldCamera.position.x - w / 2, worldCamera.position.y - h / 2, w, h);
	}

	public Rectangle getBounds(){
		return cameraBounds;
	}

    @Override
    protected void processSystem() {
		worldCamera.update();
    }
}
